// pages/zhuan_da/zhuan_da.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: 1,
    // 导航
    nav: {
      // nav_title
      nav_list: [{
        con: "全部"
      }, {
        con: "已回答"
      }, {
        con: "未回答"
      }],
      currentTab: 0
    },
    //问答
    // paySH: true,
    values: "",
  },
  // 切换nav
  swichNav: function(e) {
    var nav = this.data.nav;
    nav.currentTab = e.currentTarget.dataset.current;
    this.setData({
      nav: nav
    })
  },
  /**
   * 生命周期函数--监听页面加载zid=16&user_openid=onMvv0FREZbxVWAHxpWx2mV2UUoc&qid=41
   */
  onLoad: function(options) {
    var that = this
    var zid = options.zid
    var qid = options.qid
    var fromuser = options.fromuser
    var user_openid = options.user_openid
    var openid = wx.getStorageSync('openid')
    var bgc = wx.getStorageSync('color')
    var types = options.types
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.setData({
      zid: zid,
      qid: qid,
      user_openid: user_openid,
      openid: openid,
      fromuser: fromuser
    })
  },
  //预览
  yulan: function(e) {
    console.log(e)
    var that = this
    var index = e.target.dataset.index
    var idx = e.currentTarget.dataset.idx
    var wendaArr = that.data.qs
    console.log(wendaArr)
    var img = wendaArr.user_picture[index]
    var imgArr = wendaArr.user_picture
    wx.previewImage({
      current: img, // 当前显示图片的http链接
      urls: imgArr // 需要预览的图片http链接列表
    })
  },

  //点赞
  zanClick: function(e) {
    var that = this
    var wendaArr = that.data.qs
    console.log(e)
    var index = e.currentTarget.dataset.index
    wendaArr[index].checked = !wendaArr[index].checked
    that.setData({
      wendaArr: wendaArr
    })
  },
  // 开关
 
  //确认

  //提问
  tiwenClick: function(e) {
    console.log(e)
    var index = e.currentTarget.dataset.index
    var qid = e.currentTarget.dataset.qid
    var overFlow1 = "true"
    var that = this
    var focus = true
    that.setData({
      overFlow1: overFlow1,
      index: index,
      focus: focus,
      qid: qid
    })
  },
  //隐藏提问
  hideClick: function() {

    var overFlow1 = ""
    var that = this
    that.setData({
      overFlow1: overFlow1,

    })
  },

  hideClick: function() {
    var that = this
    var overFlow1 = ""
    that.setData({
      overFlow1: overFlow1
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    this.getAllquestion()
    // this.getSelectnew()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  getAllquestion: function() {
    var that = this
    var zid = that.data.zid
    var fromuser = that.data.fromuser
    var user_openid = that.data.user_openid
    var qid = that.data.qid
    console.log(zid, user_openid, qid)
    app.util.request({
      'url': 'entry/wxapp/Allquestion',
      data: {
        qid: qid,
        zid: zid,
        user_openid: user_openid,
        fromuser: fromuser
      },
      success: function(res) {
        console.log(res)
        if (res.data.data.if_over == 1) {
          var paySH = true
        } else {
          var paySH = false
        }
        that.setData({
          paySH: paySH,
          qs: res.data.data
        })
      }
    })
  },
  // getSelectnew: function() {
  //   var that = this
  //   var zid = that.data.zid
  //   var user_openid = that.data.user_openid
  //   // console.log(zid, user_openid)
  //   app.util.request({
  //     'url': 'entry/wxapp/Selectnew',
  //     data: {
  //       zid: zid,
  //       user_openid: user_openid
  //     },
  //     success: function(res) {
  //       var values = res.data.data.money
  //       var siwth = res.data.data
  //       if (res.data.data.steta == 1) {
  //         var paySH = true
  //       } else {
  //         var paySH = false
  //       }
  //       that.setData({
  //         paySH: paySH,
  //         values: values,
  //         siwth: siwth
  //       })
  //     }
  //   })
  // },
})